package sundun.sharding.controller;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import sundun.sharding.abnormal.entity.MigrationFail;
import sundun.sharding.abnormal.service.MigrationFailService;
import sundun.sharding.entity.ImsYesterdayAjxx;
import sundun.sharding.entity.ImsYesterdayJqxx;
import sundun.sharding.mapper.ImsYesterdayAjxxDao;
import sundun.sharding.mapper.ImsYesterdayJqxxDao;
import sundun.sharding.service.ImsYesterdayAjxxService;

import java.util.*;

@Slf4j
@RestController
@RequestMapping("/ajxx")
public class ImsYesterdayAjxxController {

    @Autowired
    private ImsYesterdayAjxxDao imsYesterdayAjxxDao;

    @Autowired
    private ImsYesterdayAjxxService imsYesterdayAjxxService;


    @GetMapping(value = "/interaction1")
    public void queryInteractionStatistics1(){
        for (int i = 0; i < 2; i++) {
            ImsYesterdayAjxx imsYesterdayJqxx = new ImsYesterdayAjxx();
            imsYesterdayJqxx.setCbdwBh("21020300001"+i);
            imsYesterdayJqxx.setSlsj(new Date());
            imsYesterdayAjxxDao.insert(imsYesterdayJqxx);
        }
    }

    /**
     * 测试数据双写
     */
    @GetMapping(value = "/insert1")
    public void  insert1(){
        ImsYesterdayAjxx ajxx = new ImsYesterdayAjxx();
        ajxx.setAjbh("aaa");

        ajxx.setAjmc("aaaaa");
        ajxx.setAjlx("02");
        ajxx.setAjzt("02");
        ajxx.setCbdwBh("02222342");
        ajxx.setCbdwMc("测试");
        ajxx.setJyaq("02");
        ajxx.setZbrXm("测试");
        ajxx.setZbrJh("测试");
        ajxx.setId(UUID.randomUUID().toString().replaceAll("-", "").substring(0,16));
        ajxx.setAddTime(new Date());
        ajxx.setZbrSfzh("测试");
        ajxx.setZbrMobile("测试");

        ajxx.setSlsj(new Date());
        ajxx.setYqsj(new Date());

        ajxx.setXbrXm("测试");
        ajxx.setXbrSfzh("测试");
        ajxx.setXbrJh("测试");
        ajxx.setLasj(new Date());
        imsYesterdayAjxxDao.insert(ajxx);
    }


    @GetMapping(value = "/interaction2")
    public void batchInsert(){
        List<ImsYesterdayAjxx> list = new ArrayList<>();
        for (int i = 0; i < 2; i++) {
            ImsYesterdayAjxx ajxx = new ImsYesterdayAjxx();
            ajxx.setId(UUID.randomUUID().toString().replaceAll("-", "").substring(0,16));
            ajxx.setCbdwBh("21020300001"+i);
            ajxx.setSlsj(new Date());
            ajxx.setAjbh("aaa");

            ajxx.setAjmc("aaaaa");
            ajxx.setAjlx("02");
            ajxx.setAjzt("02");
            ajxx.setCbdwBh("02222342");
            ajxx.setCbdwMc("测试");
            ajxx.setJyaq("02");
            ajxx.setZbrXm("测试");
            ajxx.setZbrJh("测试");
            ajxx.setAddTime(new Date());
            ajxx.setZbrSfzh("测试");
            ajxx.setZbrMobile("测试");

            ajxx.setSlsj(new Date());
            ajxx.setYqsj(new Date());

            ajxx.setXbrXm("测试");
            ajxx.setXbrSfzh("测试");
            ajxx.setXbrJh("测试");
            ajxx.setLasj(new Date());
            list.add(ajxx);
        }
        imsYesterdayAjxxService.insertBatch(list);
    }


    @Autowired
    private MigrationFailService migrationFailService;

    @GetMapping(value = "/addfail")
    public void  addfail(){
        MigrationFail imsMigrationFail = new MigrationFail();
        imsMigrationFail.setId("1");
        imsMigrationFail.setFailNum(1);
        imsMigrationFail.setInfo("测试");
        imsMigrationFail.setAddTime(new Date());
        imsMigrationFail.setUpdateTime(new Date());
        imsMigrationFail.setEndTime("2024-10-11");
        imsMigrationFail.setStartTime("2024-10-11");
        imsMigrationFail.setMigrationTable("ims_trial");
        migrationFailService.insert(imsMigrationFail);
    }

}
